<template>
  <div class="app-container">
    <el-header>
      <div class="box">
        <!-- <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        > -->
        <el-input
          v-model="input"
          placeholder="请输入资产名称或编号或品牌"
          style="margin-right: 10px; width: 15%"
        ></el-input>
        <el-select
          v-model="select"
          slot="prepend"
          style="margin-right: 10px; width: 15%"
          placeholder="请选择实训基地"
        >
          <el-option label="餐厅名" value="1"></el-option>
          <el-option label="订单号" value="2"></el-option>
          <el-option label="用户电话" value="3"></el-option>
        </el-select>
        <el-select v-model="select" slot="prepend" placeholder="请选择实训室">
          <el-option
            label="合肥市现代职业教育公共实训中心—现代服务中心"
            value="1"
          ></el-option>
          <el-option
            label="合肥市现代职业教育公共实训中心—现代服务中心"
            value="2"
          ></el-option>
          <el-option
            label="合肥市现代职业教育公共实训中心—现代服务中心"
            value="3"
          ></el-option>
        </el-select>
        <el-button
          type="primary"
          style="margin-left: 10px"
          icon="el-icon-search"
          >查询</el-button
        >
        <el-button type="primary" icon="el-icon-circle-plus-outline"
          >资产入库</el-button
        >
        <!-- </el-form> -->
      </div>
    </el-header>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['generator:user:edit']"
          >编辑</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['generator:user:remove']"
          >出库</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['generator:user:remove']"
          >调拨</el-button
        >
      </el-col>

      <right-toolbar :showSearch.sync="showSearch"></right-toolbar>
    </el-row>
    <!-- :span-method="arraySpanMethod" -->
    <el-table :data="userList" >
      <el-table-column label="资产名称" align="center" prop="id" />
      <el-table-column label="资产编号" align="center" prop="name" />
      <el-table-column label="品牌" align="center" prop="amount1" />
      <el-table-column label="规格型号" align="center" prop="amount2" />
      <el-table-column label="使用情况" align="center" prop="amount3" />
      <el-table-column label="登记日期" align="center" prop="amount4" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['generator:user:edit']"
            v-if="scope.row.id != ''"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['generator:user:edit']"
            v-else
            >入库</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-if="scope.row.id != ''"
            v-hasPermi="['generator:user:remove']"
            >出库</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-if="scope.row.id != ''"
            v-hasPermi="['generator:user:remove']"
            >调拨</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /> -->

    <!-- 添加或修改用户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>

        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listUser,
  getUser,
  delUser,
  addUser,
  updateUser,
} from "@/api/generator/user";

export default {
  name: "User",
  data() {
    return {
      // 遮罩层
      loading: true,
      input: "",
      select: "",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: [
        {
          id: "",
          name: (
            <el-link icon="el-icon-s-home">
            3D打印实训室
            </el-link>
          ),
          but: (
                    <el-button>入库</el-button>
          ),
        },
        {
          id: "消费级3D打印机",
          name: "DB298",
          amount1: "闪铸",
          amount2: "FNIDER",
          amount3: "再用",
          amount4: "2020-08-05",
        },
        {
          id: "消费级3D打印机",
          name: "DB298",
          amount1: "闪铸",
          amount2: "FNIDER",
          amount3: "再用",
          amount4: "2020-08-05",
        },
        {
          id: "消费级3D打印机",
          name: "DB298",
          amount1: "闪铸",
          amount2: "FNIDER",
          amount3: "再用",
          amount4: "2020-08-05",
        },
        {
          id: "",
          name: (
            <el-link icon="el-icon-s-home">
              {" "}普加工车间{" "}
            </el-link>
          ),
        },
        {
          id: "消费级3D打印机",
          name: "DB298",
          amount1: "闪铸",
          amount2: "FNIDER",
          amount3: "再用",
          amount4: "2020-08-05",
        },
        {
          id: "消费级3D打印机",
          name: "DB298",
          amount1: "闪铸",
          amount2: "FNIDER",
          amount3: "再用",
          amount4: "2020-08-05",
        },
        {
          id: "消费级3D打印机",
          name: "DB298",
          amount1: "闪铸",
          amount2: "FNIDER",
          amount3: "再用",
          amount4: "2020-08-05",
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        age: null,
        sex: null,
        head: null,
        phone: null,
        birthday: null,
        isVip: null,
        isPay: null,
        questionNum: null,
        correctRate: null,
        rightNum: null,
        studyTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {},
  methods: {
    // arraySpanMethod({ row, column, rowIndex, columnIndex }) {
    //   if (rowIndex === 0 || rowIndex === 4) {
    //     return [1, 2];
    //   }
    // },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userName: null,
        age: null,
        sex: null,
        head: null,
        phone: null,
        birthday: null,
        isVip: null,
        isPay: null,
        questionNum: null,
        correctRate: null,
        rightNum: null,
        studyTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getUser(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateUser(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUser(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除用户编号为"' + ids + '"的数据项？')
        .then(function () {
          return delUser(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "generator/user/export",
        {
          ...this.queryParams,
        },
        `user_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
